package com.g4.shoppingback.controller;

import com.g4.shoppingback.common.ImagesVo;
import com.g4.shoppingback.common.Result;
import com.g4.shoppingback.service.ImagesVoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@RestController
@CrossOrigin
public class ImagesVoController {


    @Autowired
    private ImagesVoService imagesVoService;

    @PostMapping("/images/upload")
    public Result upload(MultipartFile file) throws Exception{

        ImagesVo imagesVo = imagesVoService.upload(file);
        if (imagesVo == null){
            return Result.error();
        }
        return Result.ok(imagesVo);
    }

    @DeleteMapping("/images/delete")
    public Result deleteVo(String path){

        imagesVoService.deleteImages(path);

        return Result.success("图片删除成功");
    }
}
